﻿@page "/login"
@using BlazorWebAppMovies.Services
@using BlazorWebAppMovies.Models

@inject AuthService AuthService
@inject NavigationManager Navigation

<h3>登录</h3>

<EditForm Model="@loginModel" OnValidSubmit="HandleLogin">
    <DataAnnotationsValidator />
    <ValidationSummary />

    <div class="form-group">
        <label>用户名：</label>
        <InputText @bind-Value="loginModel.Username" class="form-control" />
    </div>

    <div class="form-group">
        <label>密码：</label>
        <InputText type="password" @bind-Value="loginModel.Password" class="form-control" />
    </div>

    <button type="submit" class="btn btn-primary">登录</button>
</EditForm>

@code {
    private LoginModel loginModel = new();

    private async Task HandleLogin()
    {
        if (await AuthService.LoginAsync(loginModel.Username, loginModel.Password))
        {
            Navigation.NavigateTo("/");
        }
        else
        {
            // 显示错误信息
        }
    }
}

